package com.ruoyi.web.controller.dispatch;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DispatchMonitoringItem;
import com.ruoyi.system.service.IDispatchMonitoringItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 监测项Controller
 * 
 * @author ruoyi
 * @date 2025-03-02
 */
@RestController
@RequestMapping("/system/dispatchMonitoringItem")
public class DispatchMonitoringItemController extends BaseController
{
    @Autowired
    private IDispatchMonitoringItemService dispatchMonitoringItemService;

    /**
     * 查询监测项列表
     */
    @PreAuthorize("@ss.hasPermi('system:dispatchMonitoringItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(DispatchMonitoringItem dispatchMonitoringItem)
    {
        startPage();
        List<DispatchMonitoringItem> list = dispatchMonitoringItemService.selectDispatchMonitoringItemList(dispatchMonitoringItem);
        return getDataTable(list);
    }

    /**
     * 导出监测项列表
     */
    @PreAuthorize("@ss.hasPermi('system:dispatchMonitoringItem:export')")
    @Log(title = "监测项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DispatchMonitoringItem dispatchMonitoringItem)
    {
        List<DispatchMonitoringItem> list = dispatchMonitoringItemService.selectDispatchMonitoringItemList(dispatchMonitoringItem);
        ExcelUtil<DispatchMonitoringItem> util = new ExcelUtil<DispatchMonitoringItem>(DispatchMonitoringItem.class);
        util.exportExcel(response, list, "监测项数据");
    }

    /**
     * 获取监测项详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:dispatchMonitoringItem:query')")
    @GetMapping(value = "/{monitoringItemId}")
    public AjaxResult getInfo(@PathVariable("monitoringItemId") Long monitoringItemId)
    {
        return success(dispatchMonitoringItemService.selectDispatchMonitoringItemByMonitoringItemId(monitoringItemId));
    }

    /**
     * 新增监测项
     */
    @PreAuthorize("@ss.hasPermi('system:dispatchMonitoringItem:add')")
    @Log(title = "监测项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DispatchMonitoringItem dispatchMonitoringItem)
    {
        return toAjax(dispatchMonitoringItemService.insertDispatchMonitoringItem(dispatchMonitoringItem));
    }

    /**
     * 修改监测项
     */
    @PreAuthorize("@ss.hasPermi('system:dispatchMonitoringItem:edit')")
    @Log(title = "监测项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DispatchMonitoringItem dispatchMonitoringItem)
    {
        return toAjax(dispatchMonitoringItemService.updateDispatchMonitoringItem(dispatchMonitoringItem));
    }

    /**
     * 删除监测项
     */
    @PreAuthorize("@ss.hasPermi('system:dispatchMonitoringItem:remove')")
    @Log(title = "监测项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{monitoringItemIds}")
    public AjaxResult remove(@PathVariable Long[] monitoringItemIds)
    {
        return toAjax(dispatchMonitoringItemService.deleteDispatchMonitoringItemByMonitoringItemIds(monitoringItemIds));
    }
}
